<?php  
	defined('C5_EXECUTE') or die(_("Access Denied."));
	
	$textHelper = Loader::helper("text"); 
	$ih = Loader::helper('image');
	// now that we're in the specialized content file for this block type, 
	// we'll include this block type's class, and pass the block to it, and get
	// the content
?>
<div class="<?php echo $cssClass;?>">
	<h2><?php echo $title;?></h2>
	<p><?php echo $searchDesc;?></p>
	<?php  if (isset($error)) { ?>
		<?php echo $error?><br/><br/>
	<?php  } ?>
	<form method="get" action="<?php echo $this->url($resultTargetURL)?>" id="project-form-search" class="project-form">
		<div class="item">
			<?php  echo $form->select('projectMain', $mainTypes, array('class' => 'styled'))?>
		</div>
		<div id="searchField">
			<div class="item">
				<?php if (count($types) == 0): ?>
					<span><?php  echo t('No project type defined. Please create a project type.')?></span>
				<?php else:?>
					<?php  echo $form->select('projectType', $types, $cType, array('class' => 'styled'))?>
				<?php endif;?>
			</div>
			<div class="item">
				<?php if (count($locations) == 0): ?>
					<span><?php  echo t('No project location defined. Please create a project location.')?></span>
				<?php else:?>
					<?php  echo $form->select('projectLocation', $locations, $cLocation, array('class' => 'styled'))?>
				<?php endif;?>
			</div>
			<div class="item">
				<?php if (count($priceRanges) == 0): ?>
					<span><?php  echo t('No project price defined. Please create a project price.')?></span>
				<?php else:?>
					<?php  echo $form->select('projectPriceRange', $priceRanges, $cPriceRange, array('class' => 'styled'))?>
				<?php endif;?>
			</div>
			<!--div class="item">
				<?php if (count($numberRooms) == 0): ?>
					<span><?php  echo t('No Number of Room type defined. Please create a Number of room type.')?></span>
				<?php else:?>
					<?php  echo $form->select('projectNumberRoom', $numberRooms, $cNumberRoom, array('class' => 'styled'))?>
				<?php endif;?>
			</div-->
			<div class="item">
				<?php  echo $form->text('projectKeyword', $cKeyword)?>
			</div>
		</div>
		<div class="item">
		<?php  
			$ih = Loader::helper('concrete/interface');
			echo '<span id="projectSearchSubmit" class="button">';
			//print $ih->submit($buttonText, 'project-form-search', 'left');
			echo '<input type="submit" value="' . $buttonText . '" name="Submit" class="formBlockSubmitButton">';
			echo '</span>';
		?>
		</div>
	</form>
</div>
<?php if($do_search):?>
	<div class="project_search_list">
		<div id="pane1" class="scroll-pane" style="height: 410px;">
		<?php if (count($cArray) > 0):?>
			<?php
		//		$page = Page::getCurrentPage();
		//		$blocks = $page->getBlocks('Main'); 
				// disable content
				//foreach($blocks as $item){
					//$item->delete();
				//}		
				$ih = Loader::helper('image');
			?>
			<ul>
			<?php for ($i = 0; $i < count($cArray); $i++ ):
				$cobj = $cArray[$i];
				$title = $cobj->getCollectionName();
				$cLogo = null;			
				if ($cLogoID = $cobj->getAttribute('projectestate_logo')) { 
					$cLogo = File::getByID($cLogoID);
				}
			?>
				<li>
					<a class="ajax" href="<?php echo $nh->getLinkToCollection($cobj)?>" title="<?php echo $title;?>">
						<?php if($cLogo):?>
							<img src="<?php echo $cLogo->getRelativePath()?>"/>
						<?php else:?>
							<h3><?php echo $title;?></h3>
						<?php endif;?>
					</a>
				</li>
			<?php endfor;?>
			<?php if(count($cArray) < 12): $i = count($cArray);?>
				<?php while($i < 12): $i++;?>
				<li>&nbsp;</li>
				<?php endwhile;?>
			<?php elseif(count($cArray) % 4 != 0): $i = count($cArray) % 4;?>
				<?php while($i < 4): $i++;?>
				<li>&nbsp;</li>
				<?php endwhile;?>
			<?php endif;?>
			</ul>
		<?php else:?>
		<p style="margin-top:32px">
			<?php echo t($noResult)?>
		</p>
		<?php endif;?>
		<div class="clear"></div>
		</div>
	</div>
<?php endif;?>
<script type="text/javascript">
	$(function(){
		$("#projectMain").change(function(){
			changeMainType($(this).val());
		});
		changeMainType($("#projectMain").val());
		$("#project-form-search select:not(#projectMain)").change(function(){
			if($(this).val != 0){
				$("#project-form-search").submit();
			}
		});
	});	
	function changeMainType(val){
		//console.log('select type: ' + val);
		// Hide all
		$("#searchField .item").each(function(){
			$(this).hide();
			$(this).find('input,select').attr('disabled', 'disabled');			
		});
		$("#projectSearchSubmit").hide();
		if (val != '' && val != 'none') {
			// show match type
			$("#" + val).parent().show();
			$("#" + val).removeAttr('disabled');
			$("#projectSearchSubmit").show();
		}
	}
	var selectWidth = "160";
	/* No need to change anything after this */
	document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
	window.onload = Custom.init;
</script>